package test;

import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.input.ScrollEvent;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;

import javax.swing.*;
import java.awt.*;
import java.util.List;

/**
 * @author jin
 */
public class app {
    public static void main(String[] args) {
        JFrame frame = new JFrame("test");
        //无边框
//        frame.setUndecorated(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //窗口最大化
        frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
        frame.setIconImages(List.of(Toolkit.getDefaultToolkit().getImage(app.class.getResource("/images/calis.png"))));
        frame.setSize(800, 600);
        JFXPanel jfxPanel = new JFXPanel();
        frame.add(jfxPanel);
        frame.setVisible(true);

        Platform.runLater(() -> {
            WebView webView = new WebView();
            jfxPanel.setScene(new Scene(webView));
            WebEngine webViewEngine = webView.getEngine();
            webViewEngine.load("https://www.aliyun.com");
            webView.addEventFilter(ScrollEvent.SCROLL, (ScrollEvent e) -> {
                double deltaY = e.getDeltaY();
                if (e.isControlDown() && deltaY > 0) {
                    webView.setZoom(webView.getZoom() * 1.1);
                    e.consume();
                } else if (e.isControlDown() && deltaY < 0) {
                    webView.setZoom(webView.getZoom() / 1.1);
                    e.consume();
                }
            });

        });
    }
}
